package com.wiz.vo.to.wjika;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;


/**
 * 请求被扫支付API需要提交的数据
 */
public class WjPayReqData extends WjBaseData{
	private static final long serialVersionUID = 8012624815802929422L;
	
	//每个字段具体的意思请查看API文档
    private String app_id;//公众账号ID  必需，无须配置
    private String app_key;//生成签名Sign时使用
    private String merid;//店铺ID
    private String morderno;//流水号,商户系统订单号
    private String orderno;//万集卡订单号
    private String paycode;//用户支付码
    private String deviceno;//设备号
    private String sign;//验证字符串
    private Double amount;//总金额
    
    public WjPayReqData(){
    	setApp_id(APP_ID);
    }
    
    public List<NameValuePair> toFormParamsList(){
    	List<NameValuePair> formparams=new ArrayList<NameValuePair>();
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            Object obj;
            try {
                obj = field.get(this);
                if(obj!=null){
                    formparams.add(new BasicNameValuePair(field.getName(), String.valueOf(obj)));
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return formparams;
    }
    
    public String toSign(){//若以后参数增多，可采用取类参数排序的方式
    	StringBuffer sb = new StringBuffer();
    	if(amount != null){
    		sb.append("amount=").append(amount.doubleValue());
    	}
    	sb.append("app_id=").append(app_id);
    	if(StringUtils.isNotBlank(deviceno)){
    		sb.append("deviceno=").append(deviceno);
    	}
    	if(StringUtils.isNotBlank(merid)){
    		sb.append("merid=").append(merid);
    	}
    	if(StringUtils.isNotBlank(morderno)){
    		sb.append("morderno=").append(morderno);
    	}
    	if(StringUtils.isNotBlank(paycode)){
    		sb.append("paycode=").append(paycode);
    	}
    	sb.append(APP_KEY);
    	return sb.toString();
    }

	public String getApp_id() {
		return app_id;
	}

	public void setApp_id(String app_id) {
		this.app_id = app_id;
	}

	public String getApp_key() {
		return app_key;
	}

	public void setApp_key(String app_key) {
		this.app_key = app_key;
	}

	public String getMerid() {
		return merid;
	}

	public void setMerid(String merid) {
		this.merid = merid;
	}

	public String getMorderno() {
		return morderno;
	}

	public void setMorderno(String morderno) {
		this.morderno = morderno;
	}

	public String getOrderno() {
		return orderno;
	}

	public void setOrderno(String orderno) {
		this.orderno = orderno;
	}

	public String getPaycode() {
		return paycode;
	}

	public void setPaycode(String paycode) {
		this.paycode = paycode;
	}

	public String getDeviceno() {
		return deviceno;
	}

	public void setDeviceno(String deviceno) {
		this.deviceno = deviceno;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

}
